package net.jwtools.tmt.ui.util;

import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JPanel;

import org.springframework.richclient.command.AbstractCommand;
import org.springframework.richclient.command.CommandGroup;
import org.springframework.richclient.command.CommandGroupJComponentBuilder;
import org.springframework.richclient.command.config.CommandButtonConfigurer;

import com.l2fprod.common.swing.JLinkButton;
import com.l2fprod.common.swing.JOutlookBar;
import com.l2fprod.common.swing.JTaskPane;
import com.l2fprod.common.swing.JTaskPaneGroup;
import com.l2fprod.common.swing.PercentLayout;

public class JTaskPaneGroupBuilder extends CommandGroupJComponentBuilder {

	   private JTaskPane taskPane = new JTaskPane();

	    private CommandButtonConfigurer commandButtonConfigurer = new JTaskPaneCommandButtonConfigurer();

	    protected JComponent buildRootComponent(AbstractCommand command) {
			return taskPane;
		}

		/*
	     * (non-Javadoc)
	     * @see org.springframework.richclient.command.CommandGroupJComponentBuilder#buildRootComponent(org.springframework.richclient.command.CommandGroup)
	     */
	    protected JComponent buildRootComponent(CommandGroup command) {
	        return taskPane;
	    }

	    /*
	     * (non-Javadoc)
	     * @see org.springframework.richclient.command.CommandGroupJComponentBuilder#buildChildComponent(javax.swing.JComponent,
	     *      org.springframework.richclient.command.AbstractCommand, int)
	     */
	    protected JComponent buildChildComponent(JComponent parentComponent, AbstractCommand command, int level) {
	        // filter out seperators
	        if (command != null) {
	            JLinkButton button = new JLinkButton();
	            command.attach(button, commandButtonConfigurer);

	            parentComponent.add(button);
	            return button;
	        }
	        return null;
	    }

	    /*
	     * (non-Javadoc)
	     * @see org.springframework.richclient.command.CommandGroupJComponentBuilder#buildGroupComponent(javax.swing.JComponent,
	     *      org.springframework.richclient.command.CommandGroup, int)
	     */
	    protected JComponent buildGroupComponent(JComponent parentComponent, CommandGroup command, int level) {
	        JTaskPaneGroup panel = new JTaskPaneGroup();
	        panel.setLayout(new PercentLayout(PercentLayout.VERTICAL, 0));
	        panel.setOpaque(false);

	        taskPane.add(command.getText(), panel);

	        return panel;
	    }


}
